const { ccclass, property } = cc._decorator


/**
 * 基类, 目前有：单例、
 */
export default class BaseClass<K extends BaseClass<K>> {

    protected static _instance
    /**
     * 获取一个单例
     *  
     * @param args 最多支持5个参数
     * @returns {any}
     */
    public static instance<T extends BaseClass<T>>(this: new (...args: any[]) => T, ...args: any[]): T {
        let Class: any = this
        if (!(<any>this)._instance) {
            let argsLen: number = args.length
            if (argsLen == 0) {
                (<any>this)._instance = new this()
            } else if (argsLen == 1) {
                (<any>this)._instance = new this(args[0])
            } else if (argsLen == 2) {
                (<any>this)._instance = new this(args[0], args[1])
            } else if (argsLen == 3) {
                (<any>this)._instance = new this(args[0], args[1], args[2])
            } else if (argsLen == 4) {
                (<any>this)._instance = new this(args[0], args[1], args[2], args[3])
            } else if (argsLen == 5) {
                (<any>this)._instance = new this(args[0], args[1], args[2], args[3], args[4])
            }
        }
        return (<any>this)._instance
    }

    public static get ins() {
        if (!this._instance) {
            this._instance = new (<any>this)()
        }
        return this._instance
    }

    public static destroy() {
        let Class: any = this
        Class.instance = null
    }
}
